<?php

class Shopping_Plugin extends Zend_Controller_Plugin_Abstract {

    function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
        $module = $this->getRequest()->getModuleName();
        Zend_Registry::set("controller", $this->getRequest()->getControllerName());
        $layoutInstance = Zend_Layout::startMvc(array(
                    'layout' => 'layout',
                    'layoutPath' => APP_PATH . "/layouts/scripts/" . $module . "/"
                ));
        $view = $layoutInstance->getView();
        $view->setHelperPath(APP_PATH . '/layouts/helpers');
        if ($module == 'admin' && $request->getControllerName() != 'index') {
            $auth = Zend_Auth::getInstance();
            if (!$auth->hasIdentity()) {
                Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->gotoUrl("/admin/index");
            }
        }
    }

}

?>
